package tools

import (
	"google.golang.org/protobuf/types/known/timestamppb"
	"time"
)

// TimestampToStr   随便匹配 精度丢失
func TimestampToStr(timestamp *timestamppb.Timestamp, TimeFormat string) string {
	timeString := timestamp.AsTime().Format(TimeFormat)
	return timeString
}

// TimeStrToStamp  强制批评 Forced to match
func TimeStrToStamp(timeString, TimeFormat string) *timestamppb.Timestamp {
	//contx.TimeFormatMongo
	parse, err := time.Parse(TimeFormat, timeString)
	if err != nil {
		panic(err)
	}
	return timestamppb.New(parse)
}
func TimeToStamp(t time.Time, TimeFormat string) *timestamppb.Timestamp {
	//contx.TimeFormatMongo
	parse, err := time.Parse(TimeFormat, t.Format(TimeFormat))
	if err != nil {
		panic(err)
	}
	return timestamppb.New(parse)
}
